<HTML><HEAD><TITLE>register_for_notification(?X, +Tag, ?Receiver)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(tentative)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>register_for_notification(?X, +Tag, ?Receiver)</H1>
Constraint implementation: register for notification
<DL>
<DT><EM>X</EM></DT>
<DD>A non-free term, usually a tentative variable
</DD>
<DT><EM>Tag</EM></DT>
<DD>A user-defined term
</DD>
<DT><EM>Receiver</EM></DT>
<DD>A notification-receiver (input or output)
</DD>
</DL>
<H2>Description</H2>

	<P>
	This is part of the interface for implementing tentative constraints.
	It sets up a receiver in the sense of lib(notify_ports), such
	that every time the tentative value of X changes, a message
	is sent to this receiver. The message has the form
	</P><PRE>
		Tag:chg(Old,New)
	</PRE><P>
	where Tag is the parameter given here in the setup (e.g. the
	index of a variable within the constraint where it occurs),
	Old is the tentative value before the change, and New the
	tentative value after the change.
	</P><P>
	The same receiver can register for many variables. Messages
	from the different variables are distinguished by their Tag.
	</P><P>
	Such a receiver would typically be used by a demon that is woken
	up on tentative value change (tent_chg of tentative), to obtain
	precise information about the changes that caused the wakeup.
	</P>
    
<H2>Examples</H2>
<PRE>
    tent_trace_array(Stream, Name, Xs) :-
	    ( foreacharg(X,Xs,I), param(Stream,Name) do
		register_for_notification(X, I, Receiver),
		suspend(tent_trace_demon(Stream, Name, Receiver, Susp),
			1, X-&gt;tent_chg, Susp)
	    ).

	:- demon tent_trace_demon/4.
	tent_trace_demon(Stream, Name, Receiver, Susp) :-
	    foreachnotification(tent_trace_demon,
		    I:Notification, [Stream, Name], Receiver, Status, (
		printf(Stream, "%w[%w]: %w%n", [Name,I,Notification])
	    )),
	    ( Status = closed -&gt;
		writeln(Stream, Name:Status),
		kill_suspension(Susp)
	    ; true ).
    </PRE>
<H2>See Also</H2>
<A HREF="../../lib/notify_ports/index.html">library(notify_ports)</A>
</BODY></HTML>
